const { DataTypes } = require('sequelize')

const seq = require('../db/seq')

const Video = seq.define(
  'edu_video',
  {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      comment: '视频ID'
    },
    course_id: {
      type: DataTypes.INTEGER(11),
      allowNull: false,
      comment: '课程ID'
    },
    chapter_id: {
      type: DataTypes.INTEGER(11),
      allowNull: false,
      comment: '章节ID'
    },
    title: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '节点名称'
    },
    video_source_id: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '云端视频资源'
    },
    video_original_name: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '原始文件名称'
    },
    sort: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      defaultValue: 0,
      comment: '排序字段'
    },
    play_count: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      defaultValue: 0,
      comment: '播放次数'
    },
    is_free: {
      type: DataTypes.TINYINT.UNSIGNED,
      allowNull: false,
      defaultValue: 0,
      comment: '是否可以试听：0收费 1免费'
    },
    duration: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '视频时长（秒）'
    },
    status: {
      type: DataTypes.STRING(20),
      allowNull: false,
      defaultValue: 'Empty',
      comment: 'Empty未上传 Transcoding转码中  Normal正常'
    },
    size: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      defaultValue: 0,
      comment: '视频源文件大小（字节）'
    },
    version: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      defaultValue: 1,
      comment: '乐观锁'
    },
    gmt_create: {
      type: DataTypes.DATE,
      allowNull: false,
      comment: '创建时间'
    },
    gmt_modified: {
      type: DataTypes.DATE,
      allowNull: false,
      comment: '更新时间'
    }
  },
  {
    timestamps: false
  }
)

//Video.sync({ alter: true })

module.exports = Video
